package com.bjsxt.service.imp;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bjsxt.commons.DataGridModel;
import com.bjsxt.mapper.DrugMapper;
import com.bjsxt.pojo.Drug;
import com.bjsxt.pojo.DrugExample;
import com.bjsxt.pojo.DrugExample.Criteria;
import com.bjsxt.service.DrugService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
/**
 * @author clw
 */
@Service
public class DrugServiceImpl implements DrugService {
	@Autowired
	private DrugMapper drugMapper;
	/**
	 * 删除过期药品
	 */
	@Override
	public void delOverdueDrug(Integer drugid) {
		this.drugMapper.deleteByPrimaryKey(drugid);
	}
	/**
	 * 显示所有过期的药品
	 */
	@Override
	public DataGridModel findOverdueDrug(Integer page, Integer rows) {
		PageHelper.startPage(page, rows);
		DrugExample px=new DrugExample();
		Criteria c=px.createCriteria();
		c.andDrugexpdateLessThanOrEqualTo(new Date());
		List<Drug> list=this.drugMapper.selectByExample(px);
		PageInfo<Drug> p=new PageInfo<>(list);
		Long total =p.getTotal();
		DataGridModel dgm=new DataGridModel();
		dgm.setRows(list);
		dgm.setTotal(total);
		return dgm;
	}
}
